/**
 * @file       Char.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Char.h"
#include "errorcode.h"

namespace NS_LCD_AFW
{

CChar::CChar() :
		m_cChar(' ')
{
	this->setFocusable(true);
	this->setHightlightable(true);
	this->setCursorable(true);
	this->getRect().setHight(1);
	this->getRect().setWidth(1);
}

CChar::~CChar()
{
}

void CChar::setChar(char c)
{
	this->m_cChar = c;
}

char CChar::getChar() const
{
	return this->m_cChar;
}

int CChar::onDraw(IDisplay *pDisplay)
{
	int iRet = ERR_SUCCESS;
	if (ERR_SUCCESS != (iRet = CFrame::onDraw(pDisplay)))
	{
		return iRet;
	}

	pDisplay->writeChar(this->getPosition().getX(), this->getPosition().getY(),
			this->getChar());

	if (this->hasCursor())
	{
		pDisplay->setCursor(this->getPosition().getX(), this->getPosition().getY());
		pDisplay->showCursor();
	}

	return iRet;
}

int CChar::onLeftKeyPress()
{
	this->setHightlight(false);
	this->setFocus(false);
	return CFrame::onLeftKeyPress();
}

int CChar::onRightKeyPress()
{
	this->setHightlight(false);
	this->setFocus(false);
	return CFrame::onRightKeyPress();
}

int CChar::onEnterKeyPress()
{
	return onRightKeyPress();
}

int CChar::onCreate()
{
	this->getRect().setHight(1);
	this->getRect().setWidth(1);
	return CFrame::onCreate();
}

int CChar::onEscKeyPress()
{
	return onLeftKeyPress();
}

int CChar::onUpKeyPress()
{
	++m_cChar;
	return this->invalidate();
}

int CChar::onDownKeyPress()
{
	--m_cChar;
	return this->invalidate();
}

void CChar::onSetFocus()
{
	this->setCursor(true);
}

void CChar::onLostFocus()
{
	this->setCursor(false);
}

} /* namespace NS_LCD_AFW */
